package com.badlogic.androidgames.game;

import android.graphics.Rect;

public class CollisionManager {
	
    private static boolean result;
    private static Rect r1;
    private static Rect r2;
	
    private CollisionManager() {}
    
    public static boolean OnCollision(GameObject go1, GameObject go2)
    {
    	if(go1.rectangle.intersect(go2.rectangle))
    		return true;
    	else
    		return false;
    }
    
    public static boolean OnCollision(Rect rect1, Rect rect2)
    {
    	if(rect1.intersects(rect2.left, rect2.top, rect2.right, rect2.bottom))
    		return true;
    	else
    		return false;
    }

    public static boolean CheckCollision(GameObject go1, GameObject go2, float oldPosX, float oldPosY, String side, float speed)
    {
    	go1.UpdateBounds();
    	go2.UpdateBounds();
    	
    	r1 = go1.rectangle;
    	r2 = go2.rectangle;
    	
        if(side == "left")
        	result = (r1.intersect(r2) && (r1.left + r1.width()) - (r1.left - oldPosX) - speed <= r2.left);
        if(side == "top")
        	result = (r1.intersect(r2) && r1.left+ r1.height() - (r1.left - oldPosY) - speed <= r2.top);
        if(side == "right")
    	   	result = (r1.intersect(r2) && r1.left + (oldPosX - r1.left) >= ((go2.pos.x * 2) + go2.size.x));
        if(side == "bottom")
        	result = (r1.intersect(r2) && r1.top + (oldPosY - r1.top) + speed >= (r2.top + r2.height()));

        return result;
    }
}
